Vue.config.debug = true;// 开启vue 调试功能
var vm = new Vue({
	el:"#container",
			data:{
				pageOrder:1,
				totalCount:'',
				pageSize:'',
				pageCount:'',
				data:'',
				messages:[],
				unreadMsgCount:'',
				unreadRemindCount:'',
				reminds:[],
				orders:[],

			},
			mounted:function(){
				this.$nextTick(function(){
					var pathname=location.pathname;
					this.noRead();
					if(pathname=='/pages/mine/message.html'){
						this.message();
						this.noReadMes_rem();
						//上拉加载调用
						refresh(this.refreshData());
						mui.init();
						(function($) {
							var btnArray = ['确认', '取消'];
							//第二个demo，向左拖拽后显示操作图标，释放后自动触发的业务逻辑
							$('#OA_task_1').on('slideleft', '.mui-table-view-cell', function(event) {
								var elem = this;
								mui.confirm('确认删除该条记录？', '提示', btnArray, function(e) {
									if (e.index == 0) {
										var idStr=jQuery(elem).find('data').text();
										console.log(idStr)
										elem.parentNode.removeChild(elem);
										post('/advisor/msg/remove',{messageIdStr:idStr},function(res){
						            		toast('删除成功')
						            	});

									} else {
										setTimeout(function() {
											$.swipeoutClose(elem);
										}, 0);
									}
								});
							});

						})(mui);
					}
					if(pathname=='/pages/mine/remind.html'){
						this.remind();
						this.noReadMes_rem();
						mui.init();
						(function($) {
							var btnArray = ['确认', '取消'];
							//第二个demo，向左拖拽后显示操作图标，释放后自动触发的业务逻辑
							$('#OA_task_1').on('slideleft', '.mui-table-view-cell', function(event) {
								var elem = this;
								mui.confirm('确认删除该条记录？', '提示', btnArray, function(e) {
									if (e.index == 0) {
										var idStr=jQuery(elem).find('data').text();
										elem.parentNode.removeChild(elem);
										post('/advisor/msg/remove',{messageIdStr:idStr},function(res){
						            		toast('删除成功')
						            	});

									} else {
										setTimeout(function() {
											$.swipeoutClose(elem);
										}, 0);
									}
								});
							});

						})(mui);
						//上拉加载调用
						refresh(this.refreshDataRemind());
					}
				});
			},
			methods:{
				// 未读消息数
				noRead:function(){
					noParamsGet('/advisor/msg/unread-count',function(res){
						vm.data=res.data;
						if(res.data>9){
							vm.data='9+'
						}
					})
				},
	            // 消息
	            noReadMes_rem:function(){
	            	noParamsGet('/advisor/msg/unread-summary',function(res){
						vm.unreadMsgCount =res.data.productUnReadMsgCount;
						vm.unreadRemindCount =res.data.sysNoticeUnReadCount;
						if(vm.unreadMsgCount==0){
							$('.mess-circle1').hide()
						}
						if(vm.unreadRemindCount==0){
							$('.mess-circle2').hide()
						}
					});
	            },
	            message:function(){
	            	loader.init();
	            	get('/advisor/msg/list',{currentPage:vm.pageOrder,messageType:'PRODCUT_DYNAMIC'},function(res){
						vm.messages=vm.messages.concat(res.data.resultList);
						vm.totalCount=res.data.totalCount;
						vm.pageSize=res.data.pageSize;
						vm.pageCount=Math.ceil(vm.totalCount / vm.pageSize);
						for(i=0;i<vm.messages.length;i++){
							if(vm.messages[i].messageType=='PRODCUT_DYNAMIC'){
								vm.messages[i].isA='class-a';
								vm.messages[i].isB='class-b';
								vm.messages[i].isC='class-b';
							}/*
							if(vm.messages[i].messageType=='CLIENT_DYNAMIC'){
								vm.messages[i].isA='class-b';
								vm.messages[i].isB='class-a';
								vm.messages[i].isC='class-b';
							}
							if(vm.messages[i].messageType=='SYSTEM_NOTICE'){
								vm.messages[i].isA='class-b';
								vm.messages[i].isB='class-b';
								vm.messages[i].isC='class-a';
							}*/
							if(vm.messages[i].readed==false){
								vm.messages[i].isD='white';
							}else{
								vm.messages[i].isD='gray';
							}
						}
						//滚动到底部文字判断
						if(res.data.resultList.length < 10){
							refreshText('到底了哦！')
						}else{
							refreshText('上拉加载更多数据')
						}
						if(vm.totalCount == 0){
							$('.no-message').show();
							$('.mine-message').hide();
							refreshText('')
						}else{
							$('.no-message').hide();
							$('.mine-message').show();
						}
						if(vm.messages.length <10){
							refreshText('')
						}
						loader.remove();
					});
	            },
	            //提醒
	            remind:function(){
	            	loader.init();
	            	get('/advisor/msg/list',{currentPage:vm.pageOrder,messageType:'SYSTEM_NOTICE'},function(res){
						vm.reminds=vm.reminds.concat(res.data.resultList);
						vm.totalCount=res.data.totalCount;
						vm.pageSize=res.data.pageSize;
						vm.pageCount=Math.ceil(vm.totalCount / vm.pageSize);
						for(i=0;i<vm.reminds.length;i++){
							if(vm.reminds[i].messageType=='SYSTEM_NOTICE'){
								vm.reminds[i].isB='iconfont-blue';
							}
							if(vm.reminds[i].readed==false){
								vm.reminds[i].isD='white';
							}else{
								vm.reminds[i].isD='gray';
							}
						}
						//滚动到底部文字判断
						if(res.data.resultList.length < 10){
							refreshText('到底了哦！')
						}else{
							refreshText('上拉加载更多数据')
						}
						if(vm.totalCount == 0){
							$('.no-message').show();
							$('.mine-message').hide();
							refreshText('')
						}else{
							$('.no-message').hide();
							$('.mine-message').show();
						}
						if(vm.reminds.length <10){
							refreshText('')
						}
						loader.remove();
					});
	            },
				refreshData:function(){
					return function(){
						if(vm.pageCount>vm.pageOrder){
							vm.pageOrder++;
							console.log(vm.pageOrder)
							vm.message();
						}else{
							refreshText('到底了哦！')
						}
					}
				},
				refreshDataRemind:function(){
					return function(){
						if(vm.pageCount>vm.pageOrder){
							vm.pageOrder++;
							console.log(vm.pageOrder)
							vm.remind();
						}else{
							refreshText('到底了哦！')
						}
					}
				},
			},
		})
